package com.wh.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wh.system.dao.PermissionDao;
import com.wh.system.dao.RoleMenuDao;
import com.wh.system.dto.RoleMenuDto;
import com.wh.system.pojo.Permission;
import com.wh.system.pojo.RoleMenu;
import com.wh.system.service.IRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleMenuServiceimpl implements IRoleMenuService {


    @Autowired
    private RoleMenuDao roleMenuDao;
    @Override
    public void add(RoleMenu roleMenu) {
        roleMenuDao.insert(roleMenu);
    }

    @Override
    public void del(Long id) {
        roleMenuDao.deleteById(id);
    }

    @Override
    public void upd(RoleMenu roleMenu) {
        roleMenuDao.updateById(roleMenu);
    }

    @Override
    public List<RoleMenu> findAll() {
        return roleMenuDao.selectList(null);
    }

    @Override
    public RoleMenu findById(Long id) {
        return roleMenuDao.selectById(id);
    }

    @Override
    public IPage<RoleMenu> findByPage(RoleMenuDto roleMenuDto){
        //1.创建查询条件
        QueryWrapper<RoleMenu> qw = new QueryWrapper<>();
        //qw.like("xxx",roleMenuDto.getXxx());
        //qw.or();
        //qw.like("xxx",roleMenuDto.getXxx());
        //2.组件分页数据
        IPage<RoleMenu> page = new Page<>(roleMenuDto.getCurrentPage(), roleMenuDto.getPageSize());
        page.setRecords(roleMenuDao.findByPage(page,qw));
        page.setTotal(roleMenuDao.selectCount(qw));
        //3.返回
        return page;
    }

    @Override
    public List<Long> findmenuByroleId(Long id) {
        return roleMenuDao.findMenuIdByRoleId(id);
    }

    @Override
    public void patchDel(List<Long> ids) {
        roleMenuDao.deleteBatchIds(ids);
    }

}
